package cn.dxh.stagefinal.service.impl;

import cn.dxh.stagefinal.bean.Buy;
import cn.dxh.stagefinal.config.PageConfig;
import cn.dxh.stagefinal.dao.BuyDao;
import cn.dxh.stagefinal.service.BuyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;

/**
 * 你可别被我给逮到了
 * 2019/12/9/周一/19:59
 * 我们遇到什么困难都不要怕!
 * 微笑面对它!
 * 消除恐惧的最好办法就是面对恐惧，坚持就是胜利!
 * 加油!奥利给!
 */
@Service
public class BuyServiceImpl implements BuyService

{
    @Autowired
    private BuyDao buyDao;

    /*//查询所有  分页
    @Override
    public List<Buy> findBuyList()
    {
        return buyDao.findBuyList();
    }*/

    //条件查询  分页 时间、供应商、状态模糊查询
    @Override
    public PageInfo findLikeList(Integer pageIndex,String beginTime, String endTime, String supplier, Integer state)
    {
        HashMap<String,Object> map = new HashMap();
        map.put("beginTime",beginTime);
        map.put("endTime",endTime);
        map.put("supplier",supplier);
        map.put("state",state);
        PageHelper.startPage(pageIndex, PageConfig.PAGE_SIZE);
        List<Buy> likeList = buyDao.findLikeList(map);
        PageInfo<Buy> pageInfo = new PageInfo<>(likeList);
        return pageInfo;
    }

    @Override
    public int insert(String id, Integer supCode, String supName, String payType, String person, String creTime, String desc, String brand, Integer code, String name, Integer price, Integer count, Integer amount)
    {
        HashMap<String,Object> map = new HashMap();
        map.put("id",id);
        map.put("supCode",supCode);
        map.put("supName",supName);
        map.put("payType",payType);
        map.put("person",person);
        map.put("creTime",creTime);
        map.put("desc",desc);
        map.put("brand",brand);
        map.put("code",code);
        map.put("name",name);
        map.put("price",price);
        map.put("count",count);
        map.put("amount",amount);
        int i = buyDao.insert(map);
        return i;
    }

    @Override
    public Buy findById(String nowId)
    {
        Buy buy = buyDao.findById(nowId);
        return buy;
    }

    @Override
    public int update(String id, Integer supCode, String supName, String payType, String person, String creTime, String desc, String brand, Integer code, String name, Integer price, Integer count, Integer amount)
    {
        HashMap<String,Object> map = new HashMap();
        map.put("id",id);
        map.put("supCode",supCode);
        map.put("supName",supName);
        map.put("payType",payType);
        map.put("person",person);
        map.put("creTime",creTime);
        map.put("description",desc);
        map.put("brand",brand);
        map.put("code",code);
        map.put("name",name);
        map.put("price",price);
        map.put("count",count);
        map.put("amount",amount);
        int i = buyDao.update(map);
        return i;
    }

    @Override
    public int updateState(String nowId,Integer state)
    {
        System.out.println("impl中的nowId="+nowId);
        int i  = buyDao.updateState(nowId,state);
        System.out.println("impl执行后i="+i);
        return i;
    }

    @Override
    public PageInfo findBackList(Integer pageIndex, String beginTime, String endTime, String supplier, Integer state)
    {
        HashMap<String,Object> map = new HashMap();
        map.put("beginTime",beginTime);
        map.put("endTime",endTime);
        map.put("supplier",supplier);
        map.put("state",state);
        PageHelper.startPage(pageIndex, PageConfig.PAGE_SIZE);
        List<Buy> likeList = buyDao.findBackList(map);
        PageInfo<Buy> pageInfo = new PageInfo<>(likeList);
        return pageInfo;
    }


    @Override
    public int delete(String deleteId)
    {
        int i = buyDao.delete(deleteId);
        return i;
    }


    //新增退单
    @Override
    public int addBackOrder(String id, Integer supCode, String supName, String payType, String person, String creTime, String desc, String brand, Integer code, String name, Integer price, Integer count, Integer amount)
    {
        HashMap<String,Object> map = new HashMap();
        map.put("id",id);
        map.put("supCode",supCode);
        map.put("supName",supName);
        map.put("payType",payType);
        map.put("person",person);
        map.put("creTime",creTime);
        map.put("desc",desc);
        map.put("brand",brand);
        map.put("code",code);
        map.put("name",name);
        map.put("price",price);
        map.put("count",count);
        map.put("amount",amount);
        int i = buyDao.addBackOrder(map);
        return i;
    }
}
